package com.jz.community.basecomm.routerUtils;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;

import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.callback.NavigationCallback;
import com.alibaba.android.arouter.launcher.ARouter;

/**
 * Created by Tony.Fan on 2018/3/12 12:00
 * <p>
 * 采用Router中间路由对外调用，跳转指定Router注入界面
 * <p>
 * 不同进程之间的携带信息 key值
 */
public class RouterCommonUtils {

    /**
     * 无参数跳转
     *
     * @param path
     */
    public static void startNoParameterActivity(final String path) {
        ARouter.getInstance().build(path).navigation();
    }

    /**
     * 回调跳转结果
     *
     * @param context
     * @param path
     * @param requestCode
     */
    public static void startNoParameterActivity(Activity context, final String path, int requestCode) {
        ARouter.getInstance().build(path).navigation(context, requestCode);
    }

    /**
     * 有参数跳转
     *
     * @param path
     */
    public static void startParameterActivity(final String path, String key, String value) {
        ARouter.getInstance().build(path)
                .withString(key, value)
                .navigation();
    }

    /**
     * 有参数、回调跳转
     *
     * @param path
     */
    public static void startParameterActivity(Activity activity, final String path, String key, String value, int requestCode) {
        ARouter.getInstance().build(path)
                .withString(key, value)
                .navigation(activity, requestCode);
    }

    /**
     * 有参数跳转
     *
     * @param path
     */
    public static void startParameterActivity(final String path, String key, int value) {
        ARouter.getInstance().build(path)
                .withInt(key, value)
                .navigation();
    }

    /**
     * 参数bundle跳转
     *
     * @param path
     * @param bundle
     */
    public static void startParamsActivity(final String path, Bundle bundle) {
        ARouter.getInstance().build(path)
                .with(bundle)
                .navigation();
    }

    /**
     * 使用两个参数的navigation方法，可以获取单次跳转的结果
     *
     * @param path
     * @param activity
     */
    public static void startActivityCallBack(final String path, final Activity activity) {
        ARouter.getInstance().build(path).navigation(activity, new NavigationCallback() {
            @Override
            public void onFound(Postcard postcard) {

            }

            @Override
            public void onLost(Postcard postcard) {

            }

            @Override
            public void onArrival(Postcard postcard) {

            }

            @Override
            public void onInterrupt(Postcard postcard) {

            }
        });
    }
}
